const MovieHttp = require("../../utils/MovieHttp")
const {handleStar} = require("../../utils/Star")
Page({
  data: {
    
  },
  onLoad: async function () {
    var res = await MovieHttp.getComingSoon()
    var movie = []
    console.log(res)
    var res = res.data.res
    res.splice(0, 3).forEach(item => {
      var { title, pic, rating, _id } = item;
      var star = rating
      console.log(item.rating)
      movie.push({
        title,
        pic,
        rating,
        _id,
        star: handleStar(star)
      })
    })
    this.setData({
      movie
    })
    var res = await MovieHttp.getInTheaters()
    var Theaters = []
    console.log(res)
    var res = res.data.res
    res.splice(0, 3).forEach(item => {
      var { title, pic, raiting, _id } = item;
      var star = raiting
      Theaters.push({
        title,
        pic,
        raiting,
        _id,
        star: handleStar(star)
      })
    })
    this.setData({
      Theaters
    })
  },
  handle250() {
    wx.navigateTo({
      url:`/pages/top250/top250`
    })
  },
  handleSoon() {
    wx.navigateTo({
      url:`/pages/soon/soon`
    })
  },
  handleMovie() {
    wx.navigateTo({
      url:`/pages/MovieIn/MovieIn`
    })
  }
})